import java.util.Arrays;
import java.util.Scanner;

public class demo02 {
//    连号区间数
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            int max=arr[i];
            int min=arr[i];
            for (int j = i; j < n; j++) {
                if(arr[j]>=max){
                    max=arr[j];
                }
                if(arr[j]<=min){
                    min=arr[j];
                }
                if(max-min==j-i){
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}
